
function AssembleQueryBox(){
    query_box = document.getElementById('QueryContent');

    if( query_box) alertToMonitor('Loaded Query Box');

    //Make the label
    //title = document.createElement('div');
    //title.class = "WindowLabel";
    //query_box.appendChild(title);

    //Make some explanitory text
    label = document.createElement('p');
    label.innerHTML = "Enter query url. (Primitive, yes.)<br>";
    query_box.appendChild(label);

    //Create an option box.  This will almost certainly be moved later.
    //format_form = document.createElement('form');
    //format_radio_1 = document.createElement('input');
    //format_radio_1.type = "radio";
    //format_radio_1.name = "ok";
    ////format_radio_1.setAttribute('name','ok');// = "From XML";
    //format_form.appendChild(format_radio_1);
    //query_box.appendChild(format_form);

    //create input field for the html.
    new_input = document.createElement('input');
    new_input.type = "text";
    new_input.value= default_url;
    new_input.id = 'QueryString';
    query_box.appendChild(new_input);

    //And the submit button.
    button = document.createElement('input');
    button.type = "button";
    button.onclick = query_database;
    button.value = "Query"
    query_box.appendChild(button);

}

function assemble_query_string(){
    //Currently quite primitive.
    query_string = document.getElementById('QueryString');
    if( query_box){
	//alertToMonitor('Assembling querry string');
    }else{
	alertToMonitor('No querry box found.');
    }
    return query_string.value;
}

function query_database(){
    var query_string = assemble_query_string();
    alertToMonitor('Query database for '+query_string);
    loadXMLDoc(query_string,parse_xml);
}
function parse_xml(){

    if( checkReadyState(xmlhttp) == false) return;
    generateRunArrayFromXML();
    fillColumnSwitch();
    Render();

}

function generateRunArrayFromXML(){
    
    var response = xmlhttp.responseXML.documentElement;
    x = response.getElementsByTagName('Run');

    alertToMonitor('Found ' + x.length + ' run'+(x.length == 1 ? "" : "s"));    
    //clear existing run array
    RunArray.splice(0,RunArray.length);
    for(var i=0; i<x.length;i++){
	RunArray[i] = new Run();
	RunArray[i].xml = x[i];
	RunArray[i].fillTags();
    }
}
